#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "common.h"
#include "nlist.h"
#include "dlink.h"
#include "flink.h"
#include "pnode.h"
#include "pcoder.h"
#include "prescan.h"
#include "display.h"
#include "popt.h"
#include "./p16e/pic16e.h"

int main(int argc, char *argv[])
{
	std::string input = argv[3];
	std::string output = argv[4];
	
	int rtcode = _main((char*)input.c_str());
	if ( rtcode == 0 )
	{
		Nlist nlist;
		PreScan preScan(&nlist);
		progUnit = preScan.scan(progUnit);
		Pcoder pcoder;			// P-code generation
		pcoder.run(progUnit);	// run it now.
		//display(progUnit, 0);
		
		if ( pcoder.errorCount == 0 )
		{
			//Optimizer opt(&pcoder);
			//opt.run();
		//	display(pcoder.mainPcode);
		//	display(pcoder.initPcode);
		//	display(pcoder.constPcode);
			PIC16E asm_gen((char*)output.c_str(), &nlist, &pcoder);
			asm_gen.run();
		}
	}
	return 0;
}
